package com.sg.business.commons.editingsupport;

import java.util.List;

import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.ViewerColumn;

import com.sg.widgets.Widgets;
import com.sg.widgets.commons.editingsupport.IEditingSupportor;
import com.sg.widgets.registry.config.ColumnConfigurator;
import com.sg.widgets.registry.config.Option;

public abstract class AbstractManagermentCategoryEditing implements IEditingSupportor {

	@Override
	public EditingSupport createEditingSupport(ColumnViewer viewer,
			ViewerColumn viewerColumn, ColumnConfigurator configurator) {
		ComboCellEditingSupport comboCellEditingSupport = new ComboCellEditingSupport(
				viewer, getItems(), getField());
		return comboCellEditingSupport;
	}

	protected abstract String getField();

	private String[] getItems() {
		Option option = (Option) Widgets.getOptionRegistry().getConfigurator(
				getOptionId());//$NON-NLS-1$
		List<Option> subOption = option.getSubOption();
		int size = subOption.size();
		String[] items = new String[size];
		for (int i=0;i<size;i++) {
			Option childOption = subOption.get(i);
			String value = childOption.getValue().toString();
			items[i] = value;
		}
		return items;
	}

	protected abstract String getOptionId();

}
